Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix patching WorkloadRebalancer failed due to misuse of shared slices #4875

Merged
merged 1 commit into from
May 6, 2024

Conversation

chaosi-zju
Copy link
Member

What type of PR is this?

/kind bug

What this PR does / why we need it:

fix patching WorkloadRebalancer failed due to misuse of shared slices.

in previous code:

// get previous status and update basing on it
newStatus = rebalancer.Status
if len(newStatus.ObservedWorkloads) == 0 {
	newStatus = c.buildWorkloadRebalancerStatus(rebalancer)
}

actually newStatus and rebalancer.Status shared the slice of rebalancer.Status.ObservedWorkloads.

if this slice didn't change from nil to non-nil or occurs expansion, modification to newStatus will also be applied to the rebalancer.Status, which will lead to patch status failed.

Which issue(s) this PR fixes:

Fixes part of #4840

Special notes for your reviewer:

Does this PR introduce a user-facing change?:


@karmada-bot karmada-bot added the kind/bug Categorizes issue or PR as related to a bug. label Apr 28, 2024
@karmada-bot karmada-bot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Apr 28, 2024
@chaosi-zju
Copy link
Member Author

chaosi-zju commented Apr 28, 2024

@XiShanYongYe-Chang @RainbowMango

Hello, sorry for this bug, please help review once more.

In previous code:

// get previous status and update basing on it
newStatus = rebalancer.Status
if len(newStatus.ObservedWorkloads) == 0 {
	newStatus = c.buildWorkloadRebalancerStatus(rebalancer)
}

Actually newStatus and rebalancer.Status shared the slice of rebalancer.Status.ObservedWorkloads.

If this slice didn't change from nil to non-nil or occurs expansion, modification to newStatus will also be applied to the rebalancer.Status, which will lead to patch status ignored.

@codecov-commenter
Copy link

codecov-commenter commented Apr 28, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 53.06%. Comparing base (6e5a602) to head (f672ffa).
Report is 20 commits behind head on master.

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4875      +/-   ##
==========================================
+ Coverage   52.98%   53.06%   +0.08%     
==========================================
  Files         250      251       +1     
  Lines       20421    20387      -34     
==========================================
- Hits        10820    10819       -1     
+ Misses       8881     8854      -27     
+ Partials      720      714       -6     
Flag Coverage Δ
unittests 53.06% <ø> (+0.08%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@XiShanYongYe-Chang XiShanYongYe-Chang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm

@karmada-bot karmada-bot added the lgtm Indicates that a PR is ready to be merged. label Apr 28, 2024
@chaosi-zju
Copy link
Member Author

Is there any further comments? If any other suggestions, please let me know.

@RainbowMango
Copy link
Member

@XiShanYongYe-Chang
If you want to get approval from someone else, you can cc or assign.

/assign

@XiShanYongYe-Chang
Copy link
Member

If you want to get approval from someone else, you can cc or assign.

Got it.

@RainbowMango
Copy link
Member

modification to newStatus will also be applied to the rebalancer.Status, which will lead to patch status failed.

Won't lead to patch failed, but non-ops, right? That means the patch will be ignored.

@chaosi-zju
Copy link
Member Author

Won't lead to patch failed, but non-ops, right? That means the patch will be ignored.

yes, the patch will be ignored.

@karmada-bot karmada-bot removed the lgtm Indicates that a PR is ready to be merged. label Apr 30, 2024
Copy link
Member

@RainbowMango RainbowMango left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm
/approve

@karmada-bot karmada-bot added the lgtm Indicates that a PR is ready to be merged. label May 6, 2024
@karmada-bot
Copy link
Collaborator

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: RainbowMango

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@karmada-bot karmada-bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label May 6, 2024
@karmada-bot karmada-bot merged commit c7c8f49 into karmada-io:master May 6, 2024
12 checks passed
@RainbowMango
Copy link
Member

What's the next PR blocked by this?

@chaosi-zju
Copy link
Member Author

What's the next PR blocked by this?

#4860

@chaosi-zju
Copy link
Member Author

What's the next PR blocked by this?

or #4876 if you prefer

@RainbowMango
Copy link
Member

I can review them but please also ask for review from controller owners.

@chaosi-zju
Copy link
Member Author

I can review them but please also ask for review from controller owners.

ok

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. kind/bug Categorizes issue or PR as related to a bug. lgtm Indicates that a PR is ready to be merged. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants